package com.qf.shrio2203.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.shrio2203.config.CustomRealm;
import com.qf.shrio2203.user.entity.Pers;
import com.qf.shrio2203.user.entity.RolePerms;
import com.qf.shrio2203.user.entity.User;
import com.qf.shrio2203.user.entity.UserRole;
import com.qf.shrio2203.user.service.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author shoush
 * @since 2023-02-08
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    UserRoleService userRoleService;
    @Autowired
    RoleService roleService;
    @Autowired
    RolePermsService rolePermsService;
    @Autowired
    PersService persService;

    @PostMapping("/login")
    public String login(String username, String password, boolean rememberMe) {
        Subject subject = SecurityUtils.getSubject();

        //设置免登录信息---->rememberMe 给usernamePasswordToken
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password, rememberMe);
        subject.login(usernamePasswordToken);

        return "redirect:/home.html";
    }

    @PostMapping("/register")
    public String regist(User user) {
        userService.regist(user);
        //
        return "redirect:/login.html";
    }

}
